package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PurchaseInfo;
import com.ruoyi.system.service.IPurchaseInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 购入成本管理Controller
 * 
 * @author fxk
 * @date 2023-06-21
 */
@RestController
@RequestMapping("/system/purchase_info")
public class PurchaseInfoController extends BaseController
{
    @Autowired
    private IPurchaseInfoService purchaseInfoService;

    /**
     * 查询购入成本管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:purchase_info:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseInfo purchaseInfo)
    {
        startPage();
        List<PurchaseInfo> list = purchaseInfoService.selectPurchaseInfoList(purchaseInfo);
        return getDataTable(list);
    }

    /**
     * 导出购入成本管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:purchase_info:export')")
    @Log(title = "购入成本管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseInfo purchaseInfo)
    {
        List<PurchaseInfo> list = purchaseInfoService.selectPurchaseInfoList(purchaseInfo);
        ExcelUtil<PurchaseInfo> util = new ExcelUtil<PurchaseInfo>(PurchaseInfo.class);
        util.exportExcel(response, list, "购入成本管理数据");
    }

    /**
     * 获取购入成本管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:purchase_info:query')")
    @GetMapping(value = "/{purchaseId}")
    public AjaxResult getInfo(@PathVariable("purchaseId") Long purchaseId)
    {
        return success(purchaseInfoService.selectPurchaseInfoByPurchaseId(purchaseId));
    }

    /**
     * 新增购入成本管理
     */
    @PreAuthorize("@ss.hasPermi('system:purchase_info:add')")
    @Log(title = "购入成本管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseInfo purchaseInfo)
    {
        return toAjax(purchaseInfoService.insertPurchaseInfo(purchaseInfo));
    }

    /**
     * 修改购入成本管理
     */
    @PreAuthorize("@ss.hasPermi('system:purchase_info:edit')")
    @Log(title = "购入成本管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseInfo purchaseInfo)
    {
        return toAjax(purchaseInfoService.updatePurchaseInfo(purchaseInfo));
    }

    /**
     * 删除购入成本管理
     */
    @PreAuthorize("@ss.hasPermi('system:purchase_info:remove')")
    @Log(title = "购入成本管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{purchaseIds}")
    public AjaxResult remove(@PathVariable Long[] purchaseIds)
    {
        return toAjax(purchaseInfoService.deletePurchaseInfoByPurchaseIds(purchaseIds));
    }
}
